Component({
  mixins: [],
  data: {
    poolData: {},
    number1:'100',
    number2:'200',
    number3:'300',
    labelCol: { fixedSpan: 7 },
    wrapperCol: { span: 17 },

  },
  props: {},
  didMount() {
    this.loadData();
  },
  didUpdate() { },
  didUnmount() { },
  methods: {
    async loadData() {
      const { cloud } = getApp();
      const res = await cloud.application.httpRequest({
        path: '/index.php/index/qn/getPool',
        method: 'GET',
        params:{
          shop_id:getApp().globalData.shop_id
        }
      })
      this.setData({
        poolData: res,
        number1:res.number1,
        number2:res.number2,
        number3:res.number3
      })
    },
    onChange(e) {
      let {
        detail: { value },
        currentTarget: { dataset }
      } = e;
      let { name } = dataset;
      console.log(name + ' onChange:', value);
      this.setData({ [name]: value });
    },
    onFormChange(e) {
      this.setData({
        formData: e.detail.value
      })
    },
    chooseGood(e) {
      let level = e.currentTarget.dataset.level;
      my.navigateTo({
        url: `/pages/goodwrapper/goodwrapper?level=${level}`
      });

    },
    async deleteGood(e) {
      const { cloud } = getApp();
      let level = e.currentTarget.dataset.level;
      if (level == '1') {
        const res = await cloud.application.httpRequest({
          path: '/index.php/index/qn/pool',
          method: 'POST',
          params: {
            shop_id:getApp().globalData.shop_id,
            name1: '',
            image1: '',
            coupon_id1: ''
          }
        })
        my.alert({
          content: '删除成功！',
          success: (res) => {
            this.loadData()
          }
        })
      }
      if (level == '2') {
        const res = await cloud.application.httpRequest({
          path: '/index.php/index/qn/pool',
          method: 'POST',
          params: {
            shop_id:getApp().globalData.shop_id,
            name2: '',
            image2: '',
            coupon_id2: ''
          }
        })
        my.alert({
          content: '删除成功！',
          success: (res) => {
            this.loadData()
          }
        })
      }
      if (level == '3') {
        const res = await cloud.application.httpRequest({
          path: '/index.php/index/qn/pool',
          method: 'POST',
          params: {
            shop_id:getApp().globalData.shop_id,
            name3: '',
            image3: '',
            coupon_id3: ''
          }
        })
        my.alert({
          content: '删除成功！',
          success: (res) => {
            this.loadData()
          }
        })
      }
    },
    async handleSubmit() {
      let sendData={
        shop_id:getApp().globalData.shop_id,
        number1:this.data.number1,
        number2:this.data.number2,
        number3:this.data.number3
      };
      const { cloud } = getApp();
      const res = await cloud.application.httpRequest({
        path: '/index.php/index/qn/pool',
        method: 'POST',
        params: sendData
      });
      if (res) {
        my.alert({
          title: '温馨提示',
          content: '提交成功！'
        })
        this.loadData()
      }
    }
  },
});
